﻿using System;
using System.ComponentModel;
using System.Net;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DevTools.WebClipDownload.Forms
{
    public partial class WebClipDownloadForm : XtraForm
    {
        public WebClipDownloadForm()
        {
            InitializeComponent();
        }

        private void btnDownload_Click(object sender, EventArgs e)
        {
            if (sfdDialog.ShowDialog() != DialogResult.OK)
                return;

            WebClient webClient = new WebClient();
            webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
            webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
            
            webClient.DownloadFileAsync(new Uri(txeUrl.Text), sfdDialog.FileName);
//            webClient.DownloadFile(txeUrl.Text, sfdDialog.FileName);
        }

        private void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs args)
        {
            prbProgress.Value = 0;

            MessageBox.Show("Finished.");
        }

        private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs args)
        {
            prbProgress.Value = args.ProgressPercentage;
        }
    }
}